<?php
namespace App\Rules\Concerns;


use Illuminate\Support\Str;

trait AttributeNormalize
{
    /**
     * @param string $attr
     *
     * @return array|\Illuminate\Contracts\Translation\Translator|null|string
     */
    protected function normalizeAttributeName(string $attr)
    {
        if (Str::endsWith($attr, '.*')) { // xxx.* to xxx
            $attr = substr($attr, 0,-2);
        }

        $trans_key = "validation.attributes.{$attr}";
        $attr_name = trans($trans_key);

        // if no locale, use attribute name as default
        if ($attr_name === $trans_key) {
            $attr_name = $attr;
        }

        return $attr_name;
    }
}
